<?php
/**
 * Created by PhpStorm.
 * User: 汪利东
 * Date: 2016/3/21
 * Time: 13:39
 */

namespace Admin\Controller;


use think\Controller;

class LoginController extends Controller
{

    public function index()
    {
        $this->display();
    }

    /**
     * 登录
     */
    public function handleLogin()
    {
        $r = M('admin_user')->where(I('post.'))->find();
        if (empty($r)) {
            $this->error('用户名或密码错误');
        } else {
            session('admin_user', $r);
            $rule=M('admin_group_has_user')->where(['uid'=>$r['user_id']])->join('admin_group on admin_group.id=admin_group_has_user.group_id','left')->field('rules')->find();
            session('admin_user.rules', $rule);
            $this->redirect('Index/index');
        }
    }

    /**
     * 登出
     */
    public function handleLogout()
    {
        session('admin_user', null);
        $this->redirect('Login/index');
    }
}